package Object;

import java.util.ArrayList;
import java.util.Date;

//@author A0094762W
/**
 * DSQuery is the class that is used by the Storage component to conduct
 * search on the tasks. An instance of DSQuery would then represent 1
 * serach query.
 */
public class DSQuery implements Cloneable {
	public final static int DATE_RANGE_NOT_SET = 0;
	public final static int DATE_RANGE_BEFORE_START_DATE = 1;
	public final static int DATE_RANGE_BEFORE_END_DATE = 2;
	public final static int DATE_RANGE_AFTER_START_DATE = 3;
	public final static int DATE_RANGE_AFTER_END_DATE = 4;
	public final static int DATE_RANGE_DURING_DATE = 5;

	public final static int STATUS_NOT_DONE = 1;
	public final static int STATUS_DONE = 2;
	public final static int STATUS_BOTH = 3;

	private ArrayList<String> _keyWords;
	private ArrayList<String> _tagsSet;
	private Date _taskStartDate;
	private Date _taskEndDate;
	private int _dateRange;
	private int _status;

	public DSQuery() {
		_keyWords = new ArrayList<String>();
		_tagsSet = new ArrayList<String>();
		_dateRange = DATE_RANGE_NOT_SET;
                _status = STATUS_BOTH;
	}

	public ArrayList<String> getKeyWords() {
		return _keyWords;
	}

	public Date getStartDate() {
		return _taskStartDate;
	}

	public Date getEndDate() {
		return _taskEndDate;
	}

	public int getDateRange() {
		return _dateRange;
	}

	public ArrayList<String> getTags() {
		return _tagsSet;
	}

	public int getStatus() {
		return _status;
	}

	public boolean hasKeyWord() {
		return !_keyWords.isEmpty();
	}

	public boolean hasTag() {
		return !_tagsSet.isEmpty();
	}

	public boolean hasStatus() {
		return _status != STATUS_NOT_DONE;
	}

	public boolean hasDateRange() {
		return _dateRange != DATE_RANGE_NOT_SET;
	}

	public void addKeyWord(String keyWord) {
		_keyWords.add(keyWord);
	}

	public void setStartDate(Date startDate) {
		_taskStartDate = startDate;
	}

	public void setEndDate(Date endDate) {
		_taskEndDate = endDate;
	}

	public void setDateRange(int dateRange) {
		_dateRange = dateRange;
	}

	public void addTag(String tag) {
		_tagsSet.add(tag);
	}

	public void setDoneStatus(int status) {
		_status = status;
	}
	
	//@author A0103535R
	public DSQuery copy() {
		DSQuery copy = new DSQuery();
		copy._keyWords = ((ArrayList<String>) _keyWords.clone());
		copy._tagsSet = ((ArrayList<String>) _tagsSet.clone());
		copy._taskStartDate = (Date) _taskStartDate.clone();
		copy._taskEndDate = (Date) _taskEndDate.clone();
		copy._dateRange = _dateRange;
		copy._status = _status;
		return copy;
	}
}